﻿using BaseUI;
using BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web.UI;
using Utility.Helper;

//引用下拉菜单控件命名空间
using AspxMenuItem = DevExpress.Web.MenuItem;

namespace Thksoft.MainAspx
{
    public partial class MainFrame : BasePage
    {
        #region 定义区

        protected string urlstr = string.Empty;
        private AspxMenuItem aspxMenuItem;
        private YX_BANK_LISTBLL bll = new YX_BANK_LISTBLL();

        #endregion 定义区

        #region 呈现皮肤文件

        public MainFrame()
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),
               "SKIN_NAME", "window.SystemSkinName='" + _System_Skin + "';", true);
        }

        #endregion 呈现皮肤文件

        #region 页面加载

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["TYPE"] == "API")
                {
                    AjaxResult.Success(this.Context, new BaseBLL().User);
                    return;
                }

                //IE缓存禁用，正式使用时可以打开
                Response.Cache.SetCacheability(System.Web.HttpCacheability.Server);

                FastMenu.BackgroundImage.ImageUrl = "../App_Themes/" + _System_Skin + "/Images/menubar_bg.jpg";

                //设置下拉菜单信息
                this.SetFast_Menu();
                this.SetSystem_Menu();
                this.SetHelp_Menu();
                this.SetLogOut_Menu();
                //this.Set_FavoriteMenu();

                // 用户登陆信息
                this.WriteMessage();

                //this.lblTitle.Text = ConfigurationManager.AppSettings["Title"] + "";
                this.lbl_title.Text = ConfigurationManager.AppSettings["VerTitle"] + "";
                //MethodAsync();

                BankStatus.Value = "1";
            }
        }

        #endregion 页面加载

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            #region 上方公告

            var startTopTime = " TO_DATE('" + System.DateTime.Now.ToString() + "','YYYY-MM-DD HH24:MI:SS')";
            DataTable sab1 = new SYS_ANNOUNCEMENTBLL().GetNotice(startTopTime, CurrentUserCompanyID.ToString());
            HyperLinkHint.Text = "最新公告：";
            if (sab1 != null && sab1.Rows.Count > 0 && !string.IsNullOrEmpty(sab1.Rows[0]["C_CONTENT"].ToString()))
            {
                HyperLinkHint.Text += sab1.Rows[0]["C_CONTENT"].ToString();
                HyperLinkHint.Attributes.Add("onclick ", "FORM_FABU('" + sab1.Rows[0]["C_URL"].ToString() + "')");
            }
            else
            {
                HyperLinkHint.Text += "暂时没有公告";
                HyperLinkHint.Attributes.Add("onclick ", "");
            }

            #endregion 上方公告
        }

        protected void Timer2_Tick(object sender, EventArgs e)
        {
            #region 下方公告

            var startEndTime = " TO_DATE('" + System.DateTime.Now.ToString() + "','YYYY-MM-DD HH24:MI:SS')";
            DataTable sab2 = new SYS_ANNOUNCEMENTBLL().GetNotice(startEndTime, CurrentUserCompanyID.ToString());

            if (sab2 != null && sab2.Rows.Count > 0)
            {
                if (sab2.Rows.Count >= 5 && !string.IsNullOrEmpty(sab2.Rows[4]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG5.Text = "5." + sab2.Rows[4]["C_NAME"].ToString();
                    HyperLink_KFGG5.Attributes.Add("onclick ", "FORM_FABU('" + sab2.Rows[4]["C_URL"].ToString() + "')");
                }
                else
                {
                    HyperLink_KFGG5.Text = "";//"暂时没有公告";
                    HyperLink_KFGG5.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 4 && !string.IsNullOrEmpty(sab2.Rows[3]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG4.Text = "4." + sab2.Rows[3]["C_NAME"].ToString();
                    HyperLink_KFGG4.Attributes.Add("onclick ", "FORM_FABU('" + sab2.Rows[3]["C_URL"].ToString() + "')");
                }
                else
                {
                    HyperLink_KFGG4.Text = "";//"暂时没有公告";
                    HyperLink_KFGG4.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 3 && !string.IsNullOrEmpty(sab2.Rows[2]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG3.Text = "3." + sab2.Rows[2]["C_NAME"].ToString();
                    HyperLink_KFGG3.Attributes.Add("onclick ", "FORM_FABU('" + sab2.Rows[2]["C_URL"].ToString() + "')");
                }
                else
                {
                    HyperLink_KFGG3.Text = "";//"暂时没有公告";
                    HyperLink_KFGG3.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 2 && !string.IsNullOrEmpty(sab2.Rows[1]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG2.Text = "2." + sab2.Rows[1]["C_NAME"].ToString();
                    HyperLink_KFGG2.Attributes.Add("onclick ", "FORM_FABU('" + sab2.Rows[1]["C_URL"].ToString() + "')");
                }
                else
                {
                    HyperLink_KFGG2.Text = "";//"暂时没有公告";
                    HyperLink_KFGG2.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 1 && !string.IsNullOrEmpty(sab2.Rows[0]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG1.Text = "1." + sab2.Rows[0]["C_NAME"].ToString();
                    HyperLink_KFGG1.Attributes.Add("onclick ", "FORM_FABU('" + sab2.Rows[0]["C_URL"].ToString() + "')");
                }
                else
                {
                    HyperLink_KFGG1.Text = "";//"暂时没有公告";
                    HyperLink_KFGG1.Attributes.Add("onclick ", "");
                }
            }

            #endregion 下方公告
        }

        #region 用户自定义快捷菜单信息

        protected void SetFast_Menu()
        {
            aspxMenuItem = new AspxMenuItem("", "kj", "../App_Themes/" + _System_Skin + "/Images/kj.png");
            FastMenu.Items.Add(aspxMenuItem);

            aspxMenuItem.Items.Add("我的收藏夹", "", "", "javascript:top.MessageBox.Load({Url:'/MainAspx/Favorite.aspx?ID=0',Title:'我的收藏夹',Area:['900px','700px']});", "MenuControl");
            DataTable dt = null;
            if (Application["Shortcut" + lognUser.USER_ID] != null)
            {
                dt = (DataTable)Application["Shortcut" + lognUser.USER_ID];

                string strname = string.Empty;
                if (dt.Rows.Count == 0)
                    return;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strname = "fast_" + dt.Rows[i][0].ToString();
                    urlstr = "MenuControl.aspx?ID=" + dt.Rows[i][0].ToString();
                    aspxMenuItem.Items.Add(dt.Rows[i][1].ToString(), strname, "", urlstr, "MenuControl");
                }
            }
        }

        #endregion 用户自定义快捷菜单信息

        #region 系统设置菜单

        protected void SetSystem_Menu()
        {
            aspxMenuItem = new AspxMenuItem("", "", "../App_Themes/" + _System_Skin + "/Images/sz.png");
            FastMenu.Items.Add(aspxMenuItem);
            aspxMenuItem.Items.Add("密码修改", "", "", "javascript:top.MessageBox.Load({Url:'/Module/ParameterSettings/ChangeUserPassword.aspx',Title:'密码修改',Area:['800px','435px']});", "MenuControl");
            aspxMenuItem.Items.Add("个人信息设置", "", "", "javascript:top.MessageBox.Load({Url:'/BusinessExpansion/Business/UserInfo.aspx',Title:'个人信息设置',Area:['900px','525px']});", "MenuControl");
            aspxMenuItem.Items.Add("快捷方式设置", "", "", "javascript:top.MessageBox.Alert('功能正在开发中...');", "MenuControl");
        }

        #endregion 系统设置菜单

        #region 帮助信息设置

        protected void SetHelp_Menu()
        {
            aspxMenuItem = new AspxMenuItem("", "", "../App_Themes/" + _System_Skin + "/Images/bz.png");
            FastMenu.Items.Add(aspxMenuItem);
            aspxMenuItem.Items.Add("在线反馈", "", "", "javascript:top.MessageBox.Alert('功能正在开发中...');", "MenuControl");
            //aspxMenuItem.Items.Add("使用帮助", "", "", "javascript:top.MessageBox.Load({Url:'/helpDoc/Default.aspx',Title:'使用帮助',Area:['900px','700px']});", "MenuControl");
        }

        #endregion 帮助信息设置

        #region 注销用户

        protected void SetLogOut_Menu()
        {
            aspxMenuItem = new AspxMenuItem("", "", "../App_Themes/" + _System_Skin + "/Images/zx.png", "javascript:outPage();");
            FastMenu.Items.Add(aspxMenuItem);
        }

        #endregion 注销用户

        #region 用户登陆信息

        private void WriteMessage()
        {
            string str = "";
            switch (DateTime.Today.DayOfWeek.ToString())
            {
                case "Monday":
                    str = "一";
                    break;

                case "Tuesday":
                    str = "二";
                    break;

                case "Wednesday":
                    str = "三";
                    break;

                case "Thursday":
                    str = "四";
                    break;

                case "Friday":
                    str = "五";
                    break;

                case "Saturday":
                    str = "六";
                    break;

                case "Sunday":
                    str = "日";
                    break;
            }
            //Label_LoginMessage.Text = "您好：<b>" + lognUser.USER_NAME + "</b>. 今天是" + DateTime.Today.Year + "年" + DateTime.Today.Month + "月" + DateTime.Today.Day + "日，星期" + str;
            string label_messge = "您好：" + lognUser.USER_NAME + "，今天是" + DateTime.Today.Year + "年" + DateTime.Today.Month + "月" + DateTime.Today.Day + "日，星期" + str;

            #region 上方公告

            var startTopTime = " TO_DATE('" + System.DateTime.Now.ToString() + "','YYYY-MM-DD HH24:MI:SS')";
            DataTable sab1 = new SYS_ANNOUNCEMENTBLL().GetNotice(startTopTime, CurrentUserCompanyID.ToString());
            // HyperLinkHint.Text = "最新公告：";
            string hyh = "最新公告：";
            if (sab1 != null && sab1.Rows.Count > 0 && !string.IsNullOrEmpty(sab1.Rows[0]["C_CONTENT"].ToString()))
            {
                //HyperLinkHint.Text += sab1.Rows[0]["C_CONTENT"].ToString();
                hyh = sab1.Rows[0]["C_CONTENT"].ToString();
                HyperLinkHint.Attributes.Add("onclick ", "FORM_FABU(" + sab1.Rows[0]["N_ID"].ToString() + ")");
            }
            else
            {
                //HyperLinkHint.Text += "暂时没有公告";
                hyh = "暂时没有公告";
                HyperLinkHint.Attributes.Add("onclick ", "");
            }

            #region 滚动数据传回前台

            if (Request.Form["TYPE"] == "GetJson")
            {
                List<string> list = null;
                list = new List<string>();
                list.Add(label_messge);
                list.Add(hyh);
                string json = JsonConvert.SerializeObject(list);
                Response.Write(json);
                Response.End();
            }

            #endregion 滚动数据传回前台

            #endregion 上方公告

            #region 下方公告

            var startEndTime = " TO_DATE('" + System.DateTime.Now.ToString() + "','YYYY-MM-DD HH24:MI:SS')";
            DataTable sab2 = new SYS_ANNOUNCEMENTBLL().GetNotice(startEndTime, CurrentUserCompanyID.ToString());

            if (sab2 != null && sab2.Rows.Count > 0)
            {
                if (sab2.Rows.Count >= 5 && !string.IsNullOrEmpty(sab2.Rows[4]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG5.Text = "5." + sab2.Rows[4]["C_NAME"].ToString();
                    HyperLink_KFGG5.Attributes.Add("onclick ", "FORM_FABU(" + sab2.Rows[4]["N_ID"].ToString() + ")");
                }
                else
                {
                    HyperLink_KFGG5.Text = "";//"暂时没有公告";
                    HyperLink_KFGG5.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 4 && !string.IsNullOrEmpty(sab2.Rows[3]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG4.Text = "4." + sab2.Rows[3]["C_NAME"].ToString();
                    HyperLink_KFGG4.Attributes.Add("onclick ", "FORM_FABU(" + sab2.Rows[3]["N_ID"].ToString() + ")");
                }
                else
                {
                    HyperLink_KFGG4.Text = "";//"暂时没有公告";
                    HyperLink_KFGG4.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 3 && !string.IsNullOrEmpty(sab2.Rows[2]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG3.Text = "3." + sab2.Rows[2]["C_NAME"].ToString();
                    HyperLink_KFGG3.Attributes.Add("onclick ", "FORM_FABU(" + sab2.Rows[2]["N_ID"].ToString() + ")");
                }
                else
                {
                    HyperLink_KFGG3.Text = "";//"暂时没有公告";
                    HyperLink_KFGG3.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 2 && !string.IsNullOrEmpty(sab2.Rows[1]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG2.Text = "2." + sab2.Rows[1]["C_NAME"].ToString();
                    HyperLink_KFGG2.Attributes.Add("onclick ", "FORM_FABU(" + sab2.Rows[1]["N_ID"].ToString() + ")");
                }
                else
                {
                    HyperLink_KFGG2.Text = "";//"暂时没有公告";
                    HyperLink_KFGG2.Attributes.Add("onclick ", "");
                }

                if (sab2.Rows.Count >= 1 && !string.IsNullOrEmpty(sab2.Rows[0]["C_NAME"].ToString()))
                {
                    HyperLink_KFGG1.Text = "1." + sab2.Rows[0]["C_NAME"].ToString();
                    HyperLink_KFGG1.Attributes.Add("onclick ", "FORM_FABU(" + sab2.Rows[0]["N_ID"].ToString() + ")");
                }
                else
                {
                    HyperLink_KFGG1.Text = "";//"暂时没有公告";
                    HyperLink_KFGG1.Attributes.Add("onclick ", "");
                }
            }

            #endregion 下方公告
        }

        #endregion 用户登陆信息

        #region 判断是否有超过一天的银行流水数据未匹配的

        public static bool OpenPipe()
        {
            YX_BANK_LISTBLL bankbll = new YX_BANK_LISTBLL();
            BaseBLL basbll = new BaseBLL();

            DataTable dt = bankbll.ProGetUnmatch(basbll.User.USER_COMPANY.ToString(), " sysdate-1 >= D_TRANDATE ", " D_TRANDATE desc");
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }

        ///// <summary>
        ///// 弹出状态 true 未打开 false 已打开
        ///// </summary>
        //public bool CurrentBankStatus {
        //    get{
        //    var value=this.BankStatus.Value;
        //    return value=="1"?true:false;
        //    }
        //    set {
        //        this.BankStatus.Value = value == true ? "1" : "0";
        //    }
        //}

        #endregion 判断是否有超过一天的银行流水数据未匹配的
    }
}